#!/bin/bash
host=10.142.80.21
username=BIGDATA-bdd
password=Q8k!30qL

download="d"
upload="u"
method=$1
from=$2
to=$3

## not correct operation name
[[ $method != $upload && $method != $download ]] && echo "Specify the direction of transmission!!!" && exit 1

## upload operation need local file
[[ $method == $upload && ! -e to ]] && echo "local file not exit: $to" && exit 1

## download operation need ftp file


version()
{
  echo "host:$host"
  echo "username:$username"
  echo "password:*******"
}

upload()
{
  ftp -n <<script
    open $host
    user $username $password
    binary
    prompt
    put $from $to
    close
script
}

download()
{
  ftp -n <<script
    open $host
    user $username $password
    binary
    prompt
    get $from $to
    close
script
}

if [[ $method ==  "u" ]];then
  echo "upload......"
  version
  echo "local location:$from"
  echo "ftp location:$to"
  upload
  echo "upload done!!"
  exit 0
elif [[ $method == "d" ]];then
  echo "download......"
  version
  echo "ftp location:$from"
  echo "local location:$to"
  download
  echo "download done!!"
  exit 0
fi
